import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:flutter/material.dart';
import 'package:internet_celebrity_growth_system/home.dart';
import 'package:intl/intl.dart';
import 'globals.dart' as globals;
import 'calendar_popup_view.dart';

class QuestionmarkPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return QuestionmarkPageState();
  }

}

class QuestionmarkPageState extends State<QuestionmarkPage>{

  void submitData() async {
    final url = Uri.parse(globals.url +'/question/submitQuestion');
    print(globals.token);
    var headers = {
      "token": globals.token ?? "",
      "Content-Type": "application/json",
    };
    var response = await http.get(url, headers: headers);
    if(response.statusCode==200){
      final responseData = json.decode(const Utf8Decoder().convert(response.bodyBytes));
      if (responseData['code'] == 200) {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return AlertDialog(
              title: Text("分析结果"),
              content: Text(responseData['data']),
              actions: <Widget>[
                TextButton(
                  child: Text("确定"),
                  onPressed: () {
                    Navigator.of(context).pop();

                  },
                ),
              ],
            );
          },
        );
      }else{
        print('操作失败');
        print(responseData['msg']);
      }
    }else{
      print('HTTP Error!!: ${response.statusCode}');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        title: const Text("个人定位"),),
      extendBodyBehindAppBar: true,
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Container(
          decoration: const BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0xFFB6F3EA), Colors.white70], //背景渐变色：顶部蓝色到底部灰色
                begin: Alignment.topCenter, //颜色渐变从顶部居中开始
                end: Alignment.bottomCenter, //颜色渐变从底部居中结束
              )
          ),
          child: Column(
            children: [
              SizedBox(height: 80,),
              Center(
                child:  const Text("个人定位分析",
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      fontSize: 24,
                    )),
              ),
              Text("请根据自身情况如实填写"),
    Padding(
    padding: const EdgeInsets.all(16.0), // 外部间距
    child: Column(
    children: [
      TextFormField(
        keyboardType: TextInputType.number,
        decoration: const InputDecoration(
          labelText: '1.请输入您的身高(cm)',
          labelStyle: TextStyle(fontSize: 19), // 调整字体大小
        ),
      ),
      TextFormField(
        keyboardType: TextInputType.number,
        decoration: const InputDecoration(
          labelText: '2.请输入您的体重(kg)',
          labelStyle: TextStyle(fontSize: 19), // 调整字体大小
        ),
      ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '3.您的年龄是：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("20岁以下"), value: 0),
                  DropdownMenuItem(child: Text("20-30岁"), value: 1),
                  DropdownMenuItem(child: Text("30-40岁"), value: 2),
                  DropdownMenuItem(child: Text("40岁以上"), value: 3),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '4.您的身材属于以下哪类：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("苹果型"), value: 0),
                  DropdownMenuItem(child: Text("梨形"), value: 1),
                  DropdownMenuItem(child: Text("倒三角型"), value: 2),
                  DropdownMenuItem(child: Text("沙漏型"), value: 3),
                  DropdownMenuItem(child: Text("H型"), value: 4),
                  DropdownMenuItem(child: Text("无明确受众"), value: 5),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '5.您有多少空闲时间：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("很少"), value: 0),
                  DropdownMenuItem(child: Text("有限"), value: 1),
                  DropdownMenuItem(child: Text("适中"), value: 2),
                  DropdownMenuItem(child: Text("较多"), value: 3),
                  DropdownMenuItem(child: Text("非常多"), value: 4),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '6.您的穿搭风格偏向：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("韩系"), value: 0),
                  DropdownMenuItem(child: Text("日系"), value: 1),
                  DropdownMenuItem(child: Text("欧美"), value: 2),
                  DropdownMenuItem(child: Text("休闲"), value: 3),
                  DropdownMenuItem(child: Text("复古"), value: 4),
                  DropdownMenuItem(child: Text("正式"), value: 5),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '7.您的目标受众是：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("学生"), value: 0),
                  DropdownMenuItem(child: Text("上班族"), value: 1),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '8.你想要在社交媒体上呈现的形象是：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("休闲生活"), value: 0),
                  DropdownMenuItem(child: Text("专业形象"), value: 1),
                  DropdownMenuItem(child: Text("潮流达人"), value: 2),
                  DropdownMenuItem(child: Text("知性优雅"), value: 3),
                  DropdownMenuItem(child: Text("活力青春"), value: 4),
                ],
                onChanged: (int? value) {

                },
              ),
              DropdownButtonFormField(
                decoration: InputDecoration(labelText: '9.你的穿搭预算是：',
                  labelStyle: TextStyle(fontSize: 19),),
                items: [
                  DropdownMenuItem(child: Text("高"), value: 0),
                  DropdownMenuItem(child: Text("中等"), value: 1),
                  DropdownMenuItem(child: Text("低"), value: 2),
                  DropdownMenuItem(child: Text("灵活"), value: 3),
                ],
                onChanged: (int? value) {

                },
              ),
              SizedBox(height: 20,),
              Container(
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.black), // 添加边框样式
                  borderRadius: BorderRadius.circular(15), // 可以调整边框圆角大小
                ),
                child: TextButton(
                  onPressed:(){
                    submitData();
                  },
                  child: Text("提交",
                      style: TextStyle(
                        fontSize: 19,
                      )),
                ),
              ),],),)

            ],
          ),
        )
      ),

    );
  }

}